//
//  BJFullScreenViewController.m
//  GoodTrain
//
//  Created by JW on 17/7/13.
//  Copyright © 2018年 bwx. All rights reserved.
//

#import "BJFullScreenViewController.h"
#import <BJPlayerManagerUI/BJPlayerManagerUI.h>
#import <BJPlayerManagerUI/BJPUMacro.h>
#import <BJPlayerManagerCore/BJPlayerManagerCore.h>


//View 圆角
#define ViewRadius(View,Radius)\
\
[View.layer setCornerRadius:(Radius)];\
[View.layer setMasksToBounds:YES]

@interface BJFullScreenViewController ()

@property (strong, nonatomic) NSString *vid;
@property (strong, nonatomic) NSString *token;
@property (assign, nonatomic) BOOL isNeedAD, mayDrag;


@property (strong, nonatomic) BJPUViewController *playerUIVC;

@end

@implementation BJFullScreenViewController

{
    UIView *topBarView;//顶部工具栏
}



- (instancetype)initWithVid:(NSString *)vid token:(NSString *)token isNeedAD:(BOOL)isNeedAD mayDrag:(BOOL)mayDrag
{
    self = [super init];
    if (self) {
        _vid = vid;
        _token = token;
        _isNeedAD = isNeedAD;
        _mayDrag = mayDrag;
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    ZYLog(@"进入BJY点播");
    //百家云
    [PMAppConfig sharedInstance].isNeedAD = self.isNeedAD;
    self.playerUIVC = [[BJPUViewController alloc] init];
    [self.playerUIVC setSmallScreenFrame:CGRectMake(0, SCREEN_HEIGHT * 0.4 - BJPUScreenWidth*9/16 , BJPUScreenWidth, BJPUScreenWidth*9/16)];
    [self.view addSubview:self.playerUIVC.view];
    if ([UIDevice currentDevice].orientation == UIDeviceOrientationLandscapeLeft
        || [UIDevice currentDevice].orientation == UIDeviceOrientationLandscapeRight )
        //        || [UIDevice currentDevice].orientation == UIDeviceOrientationPortraitUpsideDown)
    {
        [self.playerUIVC setScreenType:BJPUScreenType_Full];
        self.navigationController.navigationBarHidden = YES;
    }
    [self.playerUIVC setScreenType:BJPUScreenType_Full];

    [self addChildViewController:self.playerUIVC];
    [self.playerUIVC playWithVid:_vid token:_token];
    
    __weak typeof(self) weakSelf = self;
    //退出回调
    self.playerUIVC.exitBlock = ^(){
        [weakSelf dismissViewControllerAnimated:YES  completion:nil];

    };
    //播放完毕回调

    self.playerUIVC.finishPlayBlock = ^(){
        if (weakSelf.videoFinishBlock) {
            [weakSelf dismissViewControllerAnimated:YES  completion:^{
                weakSelf.videoFinishBlock();

            }];
        }        
    };

    
    
}

- (void)click_live:(UIButton *)sender{
    
    NSLog(@"点击了");
    [self dismissViewControllerAnimated:YES  completion:nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}


#pragma mark - 屏幕方向控制
//  是否支持自动转屏
- (BOOL)shouldAutorotate{
    
    //    NSLog(@"是否允许横竖屏%d",[self.playerUIVC isLockedNow]);
    return NO;
}

// 支持哪些转屏方向
- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscapeRight;
}

// 页面展示的时候默认屏幕方向（当前ViewController必须是通过模态ViewController（模态带导航的无效）方式展现出来的，才会调用这个方法）
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationLandscapeRight;
}


@end
